#![allow(unused_imports,dead_code,unused_assignments)]
use axum::{
    extract::{Form, Query, Json, Multipart,DefaultBodyLimit},
    routing::{get,post},
    response::Response,
    body::{Body, Bytes},
    Router
};
use crate::domain::OrderItemBean;
use crate::domain::OrderItemQueryRequest;
use crate::serviceimpl::order_item_service::list_my_order_items as service_list_my_order_items;
use serde::{Deserialize};
use serde_json::{Value,Map};
use std::fs;
use tower_http::{trace::TraceLayer};


#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderItemRequest {
	pub id: Option<i64>,
	pub name: Option<String>,
	pub active: Option<bool>,
	pub price: Option<f64>,
	pub amount: Option<i32>,
	pub goods_id: Option<i64>,
	pub cust_order_id: Option<i64>,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IdsRequest {
	pub ids: String,
}

pub fn order_item_cust_controller() -> Router {
	Router::new()
	.route("/listMyOrderItems", post(list_my_order_items))
}

pub async fn list_my_order_items(Json(order_item_request):Json<OrderItemRequest>) ->String {
	let cust_order_id = order_item_request.cust_order_id.unwrap_or_default();
	let order_items = service_list_my_order_items(cust_order_id).await;
	match order_items {
		Err(_) => {
			r#"{  "rows": null,  "success": true}"#.to_string()
		},
		Ok(order_items_values) => {
			let json = serde_json::to_string_pretty(&order_items_values).unwrap();

			let mut map = Map::new();
			map.insert("success".to_string(), Value::from(true));
			map.insert(
				"rows".to_string(),
				serde_json::from_str(&json).unwrap(),
			);

			let resultjson = serde_json::to_string_pretty(&map).unwrap();
			return resultjson;
		}
	}
}
